package com.chenglu.android.goodsinfo.touch;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chenglu.android.R;


import me.jessyan.autosize.internal.CustomAdapt;

/**
 * @author: lyj
 * @Created: by Copyright 2023/5/6 Guangzhou Hongma Technology Co., Ltd. All rights reserved.
 * @Description：图片集合
 */
public class PhotoFragment extends Fragment implements CustomAdapt {


    private String url;

    private PinchImageView mPhotoView;

    /**
     * 获取这个fragment需要展示图片的url
     *
     * @param url
     * @return
     */

    public static PhotoFragment newInstance(String url) {

        PhotoFragment fragment = new PhotoFragment();

        Bundle args = new Bundle();

        args.putString("url", url);

        fragment.setArguments(args);

        return fragment;

    }


    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        url = getArguments().getString("url");

    }


    @Nullable

    @Override

    public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.detail_fragment_img, container, false);

        mPhotoView = view.findViewById(R.id.photoview);

          //设置缩放类型，默认ScaleType.CENTER（可以不设置）

        // mPhotoView.setScaleType(ImageView.ScaleType.CENTER);

       //点击事件

        mPhotoView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().finish();
            }
        });
        RequestOptions options = new RequestOptions()
                .placeholder(R.color.color_f6f6f6 )
                .error(R.color.color_f6f6f6);
        Glide.with(getContext()).load(url).apply(options).override(1100, 1100).into(mPhotoView);


// .placeholder(R.mipmap.ic_launcher)//加载过程中图片未显示时显示的本地图片
// .error(R.mipmap.ic_launcher)//加载异常时显示的图片

//.centerCrop()//图片图填充ImageView设置的大小

// .fitCenter()//缩放图像测量出来等于或小于ImageView的边界范围,该图像将会完全显示
        return view;

    }

    @Override
    public boolean isBaseOnWidth() {
        return false;
    }

    @Override
    public float getSizeInDp() {
        return 812;
    }
}
